public class Test03 {
    public int longestOnes(int[] nums, int k) {
        int left = 0,right = 0,count = 0,maxLength = 0;
        while(right < nums.length){
            if(nums[right] == 0){
                count++;
            }
            if(count <= k){
                maxLength = Math.max(maxLength ,(right - left + 1));
            }else{
                while(count > k){
                    if(nums[left] == 0){
                        count--;
                    }
                    left++;
                }
            }
            right++;
        }
        return maxLength;
    }
}
